package cn.dlike.LunarCalendar.config;

import com.jfinal.config.Constants;
import com.jfinal.config.Handlers;
import com.jfinal.config.Interceptors;
import com.jfinal.config.JFinalConfig;
import com.jfinal.config.Plugins;
import com.jfinal.config.Routes;
import com.jfinal.kit.PropKit;
import com.jfinal.plugin.activerecord.ActiveRecordPlugin;
import com.jfinal.plugin.c3p0.C3p0Plugin;
import com.jfinal.render.ViewType;

import cn.dlike.LunarCalendar.beans.model._MappingKit;
import cn.dlike.LunarCalendar.util.Cron4jPlugin;

public class MainConfig extends JFinalConfig {

	@Override
	public void configConstant(Constants me) {
		PropKit.use("settings.properties");
		me.setDevMode(PropKit.getBoolean("devMode"));
		
		// debug信息先打印出来
		me.setReportAfterInvocation(false);
		// 重定向错误页
		me.setError404View("/Error404.html");
		me.setError500View("/Error500.html");
		
		// 配置默认视图
		me.setViewType(ViewType.FREE_MARKER);
		
		me.setEncoding("utf-8");

	}
	
	@Override
	public void configRoute(Routes me) {
		me.add(new CpRoute());		
	}

	@Override
	public void configPlugin(Plugins me) {
		C3p0Plugin c3p0Plugin = new C3p0Plugin(PropKit.get("connectionString"), PropKit.get("user"), PropKit.get("password"));
		me.add(c3p0Plugin);
		
		ActiveRecordPlugin arp = new ActiveRecordPlugin(c3p0Plugin);
		me.add(arp);
		me.add(new Cron4jPlugin(PropKit.use("task.properties")));
		
		_MappingKit.mapping(arp);
	}

	@Override
	public void configInterceptor(Interceptors me) {
		// TODO Auto-generated method stub
		
	}

	@Override
	public void configHandler(Handlers me) {
//		me.add(new ContextPathHandler("basePath"));
		
	}
}
